<?php
/**
 * @version 	$Id: fEvent.class.php 74 2010-03-17 06:48:21Z mylifeisskidrow@gmail.com $
 * @author 		$Author: mylifeisskidrow@gmail.com $
 * @copyright 	Copyright (c) 2010 Luu Trong Hieu. All right reserved.
 * @license 	GNU/GPL see license.php
 */

defined('IN_FLYWHEEL') or die('Restricted Access');

/**
 * Event
 * 
 * @package 	system
 * @subpackage 	event
 *
 */

class fEvent implements ArrayAccess {
	protected $value;
	protected $processed = false;
	protected $subject;
	protected $name;
	protected $param = array();	
	
	/**
	 * Construct new fEvent Object
	 *
	 * @param string $subject	subject
	 * @param string $name		event name
	 * @param array $param
	 */
	public function __construct($subject, $name, $param = array()) {
		$this->subject = $subject;
		$this->name = $name;
		$this->param = $param;		
	}
	
	/**
	 * @return string
	 */
	public function getName() {
		return $this->name;
	}
	
	/**
	 * @return string
	 */
	public function getSubject() {
		return $this->subject;
	}
	
	/**
	 * @return mixed
	 */
	public function getValue() {
		return $this->value;
	}
	
	/**
	 * @param string $name
	 */
	public function setName($name) {
		$this->name = $name;
	}
	
	/**
	 * @param boolean $processed
	 */
	public function setProcessed($processed) {
		$this->processed = (boolean) $processed;
	}
	
	/**
	 * @param string $subject
	 */
	public function setSubject($subject) {
		$this->subject = $subject;
	}
	
	/**
	 * @param mixed $value
	 */
	public function setValue($value) {
		$this->value = $value;
	}
	
	/**
	 * Is Processed
	 * 	kiem tra viec event da duoc thuc thi boi listener
	 *
	 * @return boolean
	 */
	public function isProcessed() {
		return $this->processed;
	}
	
	/**
	 * Returns true if the parameter exists (implements the ArrayAccess interface).
	 *
	 * @param  string  $name  The parameter name
	 *
	 * @return Boolean true if the parameter exists, false otherwise
	 */
	public function offsetExists($name)
	{
	  return array_key_exists($name, $this->param);
	}

	/**
	 * Returns a parameter value (implements the ArrayAccess interface).
	 *
	 * @param  string  $name  The parameter name
	 *
	 * @return mixed  The parameter value
	 */
	public function offsetGet($name)
	{
	  if (!array_key_exists($name, $this->param))
	  {
	    throw new InvalidArgumentException(sprintf('The event "%s" has no "%s" parameter.', $this->name, $name));
	  }
	
	  return $this->param[$name];
	}
	
	/**
	 * Sets a parameter (implements the ArrayAccess interface).
	 *
	 * @param string  $name   The parameter name
	 * @param mixed   $value  The parameter value 
	 */
	public function offsetSet($name, $value)
	{
	  $this->param[$name] = $value;
	}
	
	/**
	 * Removes a parameter (implements the ArrayAccess interface).
	 *
	 * @param string $name    The parameter name
	 */
	public function offsetUnset($name)
	{
	  unset($this->param[$name]);
	}
}